﻿
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>test</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
    <link href="../../layuiAdmin/lib/extend/wangeditor/style.css" rel="stylesheet">
    <script src="../../layuiAdmin/lib/extend/wangeditor/index.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">搜索框</div>
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" name="name" placeholder="请输入用户名" autocomplete="new-password" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <select name="sex">
                                    <option value="">请选择性别</option>
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </div>
                            <div class="layui-inline" id="parentId" style="width:180px ;">
                            </div>
                            <div class="layui-inline">
                                <select name="cParentId">
                                    <option value="">请选择分类名称</option>
                                </select>
                            </div>
                            <div class="layui-inline" id="test-range">
                                <div class="layui-input-inline">
                                    <input type="text" id="cStartDate" name="startDate" class="layui-input" autocomplete="new-password" placeholder="开始日期">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input type="text" id="cEndDate" name="endDate" class="layui-input" autocomplete="new-password" placeholder="结束日期">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-useradmin" layadmin-event="reset">
                                    <i class="layui-icon layui-icon-refresh layuiadmin-button-btn"></i>
                                </button>
                                <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="form-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">表单</div>
                    <div class="layui-card-body" pad15>
                        <div class="layui-form" id="popup-from">
                            <div class="layui-row">
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">用户名</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="username" style="background:#eeeeee" value="xianxin" readonly class="layui-input">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">昵称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="nickname" value="" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">性别</label>
                                            <div class="layui-input-block">
                                                <input type="radio" name="sex" value="男" title="男">
                                                <input type="radio" name="sex" value="女" title="女" checked>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">分类名称</label>
                                            <div class="layui-input-inline">
                                                <select name="cParentId">
                                                    <option value="">请选择分类名称</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">邮箱</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="email" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">头像</label>
                                        <input type="text" name="cAvatar" class="layui-input layui-hide">
                                        <img src="" style="width:200px; display:none;" name="cImgUrl" />
                                        <button type="button" class="layui-btn layui-btn-primary" id="Iconfile">
                                            <i class="layui-icon">&#xe67c;</i>上传图片
                                        </button>
                                    </div>
                                </div>
                                <div class="layui-col-xs6">
                                    <div class="layui-block">
                                        <label class="layui-form-label">资源</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="cUrl" class="layui-input" disabled readonly>
                                            <button type="button" class="layui-btn" id="Resourcefile" style="margin-top:5px">
                                                <i class="layui-icon">&#xe67c;</i>上传资源文件
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">个人简介</label>
                                <div class="layui-input-block" style="border:2px solid #eeeeee;">
                                    <div id="toolbar-container"></div>
                                    <div id="editor-container" style="height: 350px;border-top: 2px solid #eeeeee;"></div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="form-submit">提交</button>
                                    <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="form-set">赋值</button>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div style="display:none" id="impCont">
            <div class="layui-btn-container" style="text-align: center;padding-top:20px">
                <button type="button" class="layui-btn layui-btn-normal" id="imp-upload-choose">选择文件</button>
                <button type="button" class="layui-btn" id="imp-upload-action">开始上传</button>
                <progress value="0" max="100" id="imp-upload-progress" style="display: block; text-align: center; width: 95%; margin-left: 5px; "> </progress>
            </div>
        </div>
    </div>
    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script src="../../layuiAdmin/lib/extend/xm-select.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'table', 'util', 'laydate', 'upload'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table,
                element = layui.element,
                util = layui.util,
                laydate = layui.laydate,
                upload = layui.upload,
                admin = layui.admin;
            var field = {};
            var lastMonthToday = new Date(
                new Date().getTime() - 30 * 24 * 60 * 60 * 1000
            );
            //近一个月时间范围
            field.startDate = layui.util.toDateString(lastMonthToday, 'yyyy-MM-dd');
            field.endDate = layui.util.toDateString(new Date(), 'yyyy-MM-dd');
            laydate.render({
                elem: '#cStartDate',
                type: 'date',
                value: field.startDate
            });
            laydate.render({
                elem: '#cEndDate',
                type: 'date',
                value: field.endDate
            });

            //下拉框赋值
            $("select[name='cParentId']").SetSelect({
                url: '/api/DataItem/GetDataItemType',
                async: false,
                id: 'cId',
                text: 'cItemTitle',
                success: function () {
                    form.render('select');
                }
            });
            //第三方插件下拉框赋值
            xmSelect.render({
                el: '#parentId',
                name: 'parentId',
                tips: '请选择父级菜单',
                model: { label: { type: 'text' } },
                radio: true,
                clickClose: true,
                tree: {
                    show: true,
                    strict: false,
                    expandedKeys: [],
                },
                height: 'auto',
                data() {
                    var data = null;
                    admin.req({
                        type: 'get',
                        async: false,
                        url: '/api/Module/GetParentIdModule',
                        success: function (r) {
                            if (r.code == 200) {
                                data = r.data;
                            }
                        }
                    });
                    return data;
                }
            })

            //监听搜索
            form.on('submit(form-search)', function (data) {
                field = data.field;

                layer.open({
                    title: '参数',
                    content: JSON.stringify(field)
                });
            });

            //富文本编辑器
            var E = window.wangEditor; // 全局变量

            upload.render({
                elem: '#Iconfile',
                url: "/api/Upload/Upload",
                data: { type: 'userIcon' },
                done: function (res) {
                    if (res.code == 200) {
                        $("img[name='cImgUrl']").attr("src", $.GetPathUri() + res.data);
                        $("img[name='cImgUrl']").show();
                        $("#Iconfile").hide();;
                        $("input[name='cAvatar']").val(res.data);
                    } else {
                        parent.layer.msg('上传失败!\n' + res.info, { icon: 2, time: 2000 });
                    }
                }
            });
            $("img[name='cImgUrl']").on('click', function () {
                $("#Iconfile").click();
            });

            // 编辑器配置
            const editorConfig = { MENU_CONF: {} }
            editorConfig.placeholder = '请输入内容'
            editorConfig.MENU_CONF['uploadImage'] = {
                // 上传图片的配置
                server: $.GetPathUri() + '/api/base/WeditorUpload',
                allowedFileTypes: ['image/*'],
            }
            // 创建编辑器
            const editor = E.createEditor({
                selector: '#editor-container',
                config: editorConfig,
                mode: 'default' // 或 'simple' 参考下文
            })
            // 创建工具栏
            const toolbar = E.createToolbar({
                editor,
                selector: '#toolbar-container',
                config: {},
                mode: 'default' // 或 'simple' 参考下文
            });

            //赋值
            form.on('submit(form-set)', function () {
                editor.setHtml('<p>hello word</p>');
                $("img[name='cImgUrl']").attr("src", "http://www.aichunjing.com/d/file/2022-09-30/smalldef0fe6d6e0721ebe8d9115eaa47bc4e1664524670.png");
                $("img[name='cImgUrl']").show();
                $("#Iconfile").hide();
                $("#popup-from").SetFormData({ cParentId: "46874bb4-c5d1-4662-a051-005e8f560d5c", nickname: "张三", email: "986873182@qq.com", sex: "男" });
                form.render();
            })
            //保存表单
            form.on('submit(form-submit)', function (data) {
                var field = data.field; //获取提交的字段
                field.fwb = editor.getHtml();
                alert(JSON.stringify(field));
            });


            var importfile = function () {
                $.OpenTab({
                    type: 1,
                    area: ['420px', '180px'], // 宽高
                    title: "上传",
                    content: $("#impCont").html(),
                    success: function (layero, index) {
                        // 渲染
                        upload.render({
                            elem: layero.find('#imp-upload-choose'),
                            url: '/api/Scheduling/Upload', // 此处配置你自己的上传接口即可
                            auto: false,
                            exts: 'xlsx',
                            bindAction: layero.find('#imp-upload-action'),
                            before: function (obj) {
                                layero.find('#imp-upload-progress').attr('value', 0);
                                layer.msg('上传中', { icon: 16, time: 0 });
                            },// 进度条
                            progress: function (n, elem, e) {
                                layero.find('#imp-upload-progress').attr('value', n);
                                if (n == 100) {
                                    layer.msg('上传完毕', { icon: 1 });
                                }
                            },
                            done: function (res) {
                                layer.msg('上传成功');
                                layer.close(index);
                            }
                        });
                        element.render('progress', 'filter-demo');
                    }
                });
            }
            $("#Resourcefile").click(function () {
                importfile();
            });
        });
    </script>
</body>
</html>